View Javadoc

1   /*
2    * This file is part of Domingo
3    * an Open Source Java-API to Lotus Notes/Domino
4    * hosted at http://domingo.sourceforge.net
5    *
6    * Copyright (c) 2003-2006 Beck et al. projects GmbH München (http://www.bea.de)
7    *
8    * This library is free software; you can redistribute it and/or
9    * modify it under the terms of the GNU Lesser General Public
10   * License as published by the Free Software Foundation; either
11   * version 2.1 of the License, or (at your option) any later version.
12   *
13   * This library is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   * Lesser General Public License for more details.
17   *
18   * You should have received a copy of the GNU Lesser General Public
19   * License along with this library; if not, write to the Free Software
20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21   */
22  
23  package de.bea.domingo.connector.impl;
24  
25  import javax.naming.NamingException;
26  import javax.naming.Reference;
27  import javax.resource.NotSupportedException;
28  import javax.resource.ResourceException;
29  import javax.resource.cci.Connection;
30  import javax.resource.cci.ConnectionSpec;
31  import javax.resource.cci.RecordFactory;
32  import javax.resource.cci.ResourceAdapterMetaData;
33  import javax.resource.spi.ConnectionManager;
34  import javax.resource.spi.ManagedConnectionFactory;
35  
36  import de.bea.domingo.connector.DomingoConnectionFactory;
37  import de.bea.domingo.i18n.ResourceManager;
38  import de.bea.domingo.i18n.Resources;
39  
40  /***
41   * @author <a href=mailto:kurt.riede@bea.de>Kurt Riede</a>
42   */
43  public final class DomingoConnectionFactoryImpl implements DomingoConnectionFactory {
44  
45      /*** serial version ID for serialization. */
46      private static final long serialVersionUID = 4554515970618320438L;
47  
48      /*** Internationalized resources. */
49      private static final Resources RESOURCES = ResourceManager.getPackageResources(DomingoConnectionFactoryImpl.class);
50  
51      /*** Reference to the managed connection factory. */
52      private final ManagedConnectionFactory managedConnectionFactory;
53  
54      /*** Reference to the connection manager. */
55      private final ConnectionManager connectionManager;
56  
57      private Reference reference;
58  
59      /***
60       * Constructor.
61       *
62       * @param mcf the managed connection factory
63       * @param cm the connection manager
64       */
65      public DomingoConnectionFactoryImpl(final ManagedConnectionFactory mcf, final ConnectionManager cm) {
66          super();
67          this.managedConnectionFactory = mcf;
68          this.connectionManager = cm;
69      }
70  
71      /***
72       * {@inheritDoc}
73       *
74       * @see de.bea.domingo.connector.DomingoConnectionFactory#getConnection()
75       */
76      public Connection getConnection() throws ResourceException {
77          throw new NotSupportedException(RESOURCES.getString("method.not.supported.instead.1",
78                  "getConnection(ConnectionSpec spec)"));
79      }
80  
81      /***
82       * {@inheritDoc}
83       *
84       * @see de.bea.domingo.connector.DomingoConnectionFactory#getConnection(javax.resource.cci.ConnectionSpec)
85       */
86      public Connection getConnection(ConnectionSpec connectionSpec) throws ResourceException {
87          if (!(connectionSpec instanceof DomingoConnectionSpec)) {
88              throw new NotSupportedException(RESOURCES.getString("connectionspec.mustbe.instanceof.1",
89                      ConnectionSpec.class.getName()));
90          }
91          return (Connection) connectionManager.allocateConnection(managedConnectionFactory,
92                  (DomingoConnectionSpec) connectionSpec);
93      }
94  
95      /***
96       * {@inheritDoc}
97       *
98       * @see de.bea.domingo.connector.DomingoConnectionFactory#getRecordFactory()
99       */
100     public RecordFactory getRecordFactory() throws ResourceException {
101         throw new NotSupportedException(RESOURCES.getString("method.not.supported"));
102     }
103 
104     /***
105      * {@inheritDoc}
106      *
107      * @see de.bea.domingo.connector.DomingoConnectionFactory#getMetaData()
108      */
109     public ResourceAdapterMetaData getMetaData() throws ResourceException {
110         return DomingoMetaData.getInstance();
111     }
112 
113     /***
114      * {@inheritDoc}
115      *
116      * @see de.bea.domingo.connector.DomingoConnectionFactory#setReference(javax.naming.Reference)
117      */
118     public void setReference(Reference ref) {
119         reference = ref;
120     }
121 
122     /***
123      * {@inheritDoc}
124      *
125      * @see de.bea.domingo.connector.DomingoConnectionFactory#getReference()
126      */
127     public Reference getReference() throws NamingException {
128         return reference;
129     }
130 }